package com.ahdy.mapper;

import com.ahdy.entity.FamilyUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

// 2. 子女用户Mapper
@Mapper
public interface FamilyUserMapper {

        @Insert("INSERT INTO family_users(password, phone, name, nickname, avatar, gender, " +
                        "created_at, updated_at) VALUES(#{password}, #{phone}, #{name}, #{nickname}, " +
                        "#{avatar}, #{gender}, #{createdAt}, #{updatedAt})")
        @Options(useGeneratedKeys = true, keyProperty = "id")
        int insert(FamilyUser familyUser);

        @Update("UPDATE family_users SET password=#{password}, phone=#{phone}, name=#{name}, " +
                        "nickname=#{nickname}, avatar=#{avatar}, gender=#{gender}, updated_at=#{updatedAt} WHERE id=#{id}")
        int update(FamilyUser familyUser);

        @Delete("DELETE FROM family_users WHERE id=#{id}")
        int deleteById(Integer id);

        @Select("SELECT * FROM family_users WHERE id=#{id}")
        FamilyUser findById(Integer id);

        @Select("SELECT * FROM family_users")
        List<FamilyUser> findAll();

        @Select("SELECT * FROM family_users WHERE phone=#{phone}")
        FamilyUser findByPhone(String phone);

        @Select("SELECT * FROM family_users WHERE phone=#{phone} AND password=#{password}")
        FamilyUser findByPhoneAndPassword(@Param("phone") String phone, @Param("password") String password);

        // 根据老人ID查询关联的子女列表
        List<FamilyUser> findFamilyByElderlyId(Integer elderlyId);
}
